
/**
* pass the variable into $_SESSION["passVariables"]
* so that the caller can process the selected check box
* and destroy current window right after 
* this ajax process finish.
*
* @param  string  srcObject
*
*/
function passVariables(srcObject){
  
  /**
  * Check how many checked boxes 
  *
  */
  srcObject   = document.getElementsByName(srcObject);
  
  var passString = "";
  
  var passValue = new Array();
  var passIndex = 0;
  var maxItem   = srcObject.length;
  
  for(iItem = 0; iItem < maxItem; iItem++){
    
    if(srcObject[iItem].checked == true){
      
      passValue[passIndex] = srcObject[iItem].value;
      
      passIndex++;
    }
  }
  
  /**
  * We concat all the array's element
  * into 1 string
  * Since we are about to concat em,
  * we need to add "," but not at the very first element
  * the first element of array is 0th
  *
  */
  for(iElement = 0; iElement < passIndex; iElement++){
    
    if(iElement == 0){
      
      passJobId = passValue[iElement];
    }else{
      
      passJobId = passJobId + "," + passValue[iElement];
    }
  }
  //alert("passJobId : " + passJobId + " --- length : " + passJobId.length);
  /**
  * Process the ajax Call
  *
  */
  if(passJobId.length > 0){
    
    var xmlHttp =	new XMLHttpRequest();
    
    var url 		= "/ecs/tocmenu_42/controllers/passVariables.php" +"?sid="+Math.random();
  	var params 	= "passJobId="  + passJobId;
  	              
  	xmlHttp.open("POST", url, true);
  	
  	xmlHttp.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
  	xmlHttp.setRequestHeader("Content-length", params.length);
  	xmlHttp.setRequestHeader("Connection", "close");
  	
  	xmlHttp.onreadystatechange = function() {//Call a function when the state changes.
  		
  		/* Do Nothing */
  		//alert("readyState :" + xmlHttp.readyState + " and status :" + xmlHttp.status + " response: " + xmlHttp.responseText);
  	}
  	
  	xmlHttp.send(params);
  }  
}

/**
* unset $_SESSIOn["passedJobId"]
*
* @param  string  target url
*
*/
function cleanMemory(thisUrl){
  
  var result = confirm("The memory is not empty\n Would you like to clean it up? ");
  
  if(result == true){
    
    var xmlHttp =	new XMLHttpRequest();
    
    var url 		= thisUrl +"?sid="+Math.random();
    
    var params 	= "cleanUp=1";
  	              
  	xmlHttp.open("POST", url, true);
  	
  	xmlHttp.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
  	xmlHttp.setRequestHeader("Content-length", params.length);
  	xmlHttp.setRequestHeader("Connection", "close");
  	
  	xmlHttp.onreadystatechange = function() {//Call a function when the state changes.
  		
  		/* Do Nothing */
  		//alert("readyState :" + xmlHttp.readyState + " and status :" + xmlHttp.status + " response: " + xmlHttp.responseText);
  	}
  	
  	xmlHttp.send(params);
  }
}

/**
* This is a test Function
* to test if the include is success
*
* @param  void
*
*/
function sayHelloAjax(){
  
  alert("Linked ajax.js Successfuly");
}